/*
 * Project: Sudoku Hint Engine for Android
 * Copyright (C) 2010-2013 Emanuel Moecklin
 * 
 * Available under the terms of the Lesser General Public License (LGPL)
 */
package com.onegravity.sudoku.solver.data;

import java.util.List;

import com.onegravity.sudoku.solver.HintResource;
import com.onegravity.sudoku.solver.R;

/**
 * An extra region of a sudoku grid consisting of 9 cells.
 * @author Emanuel Moecklin
 */
public class ExtraRegionExtended extends Region implements ExtraRegion {

	private static final long serialVersionUID = 2187244614919158042L;

	private Grid grid;
	private ExtraRegion extraRegion;
	
    ExtraRegionExtended(ExtraRegion extraRegion, Grid grid) {
    	this.extraRegion = extraRegion;
    	this.grid = grid;
    	initRegion();
    }

    @Override
    public Cell getCell(int index) {
    	CellPosition position = extraRegion.getPosition(index);
        return grid.getCell(position.getX(), position.getY());
    }

	@Override
    public String toString() {
    	return HintResource.getString(R.string.hint_region_extraregion);
    }

    @Override
    public String toFullString() {
        return toString() + " " + extraRegion.getRegionIndex(); //$NON-NLS-1$
    }

	@Override
	public List<CellPosition> getPositions() {
		return extraRegion.getPositions();
	}

	@Override
	public CellPosition getPosition(int index) {
		return extraRegion.getPosition(index);
	}

	@Override
	public int getRegionIndex() {
		return extraRegion.getRegionIndex();
	}

    @Override
    public boolean equals(Object obj) {
    	if (! (obj instanceof ExtraRegionExtended)) return false;
    	return extraRegion.getRegionIndex() == ((ExtraRegionExtended) obj).extraRegion.getRegionIndex();
    }

	@Override
	public int compareTo(Region another) {
    	if (! (another instanceof ExtraRegionExtended)) return 1;
    	return extraRegion.getRegionIndex() < ((ExtraRegionExtended) another).extraRegion.getRegionIndex() ? -1 : 1;
	}
}